<?php
class ControlAT
{
	public function buyAT($stockid, $userid, $amount, $code, $price)
	{
		include $_SERVER['DOCUMENT_ROOT'].'scue'.'/configuration.php';
		include $_SERVER['DOCUMENT_ROOT'].'scue'.'/controller/ControlMoney.php';
		date_default_timezone_set('Asia/Bangkok');
		$date = date('Y-m-d H:i:s');
		$sql = "INSERT INTO buyAT (UserID, StockID, Price, Amount, Time) VALUES ('$userid','$stockid','$price','$amount','$date')";
		mysql_query($sql);
		$controlMoney = new ControlMoney();
		$controlMoney->subMainUserMoney($userid, $amount * $price);
	}
	
	public function sellAT($stockid, $userid, $amount, $code, $price)
	{
		include $_SERVER['DOCUMENT_ROOT'].'scue'.'/configuration.php';
		include $_SERVER['DOCUMENT_ROOT'].'scue'.'/controller/ControlStock.php';
		date_default_timezone_set('Asia/Bangkok');
		$date = date('Y-m-d H:i:s');
		$sql = "INSERT INTO sellAT (UserID, StockID, Price, Amount, Time) VALUES ('$userid','$stockid','$price','$amount','$date')";
		mysql_query($sql);
		$controlStock = new ControlStock();
		$controlStock->subUserStock($userid, $stockid, $amount);
	}
	
	public function matchAT()
	{
		
	}
}
?>